def op(q):
    for w in range(2,q):
        if q % w == 0:
            return False
    return True
 
n1=int(input())
if 999<n1<10000:
   n2=n1%1000
   n3=n1//10
   n4=n1//100
   n5=n1%100
   n6=n1%1000//10
   n7=n1//1000
   n8=n1%1000//100
   n9=n1//10%10
   n10=n1%10
   c=0
   if op(n1) and n1 > c:
       c=n1
   if op(n2) and n2 > c:
       c=n2
   if op(n3) and n3 > c:
       c=n3
   if op(n4) and n4 > c:
       c=n4
   if op(n5) and n5 > c:
       c=n5
   if op(n6) and n6 > c:
       c=n6
   if op(n7) and n7 > c:
       c=n7
   if op(n8) and n8 > c:
       c=n8
   if op(n9) and n9 > c:
       c=n9
   if op(n10) and n10 > c:
       c=n10
   print(c)
else:
   print(0)
